home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
vbcc.lha
/
vbcc
/
pasm
/
instructions.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-02-17
|
42KB
|
1,252 lines
/* $VER: pasm instructions.c V0.8 (14.02.98)
*
* This file is part of pasm, a portable PowerPC assembler.
* Copyright (c) 1997-98 Frank Wille
*
* pasm is freeware and part of the portable and retargetable ANSI C
* compiler vbcc, copyright (c) 1995-98 by Volker Barthelmann.
* pasm may be freely redistributed as long as no modifications are
* made and nothing is charged for it. Non-commercial usage is allowed
* without any restrictions.
* EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
* SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
*
*
* v0.8 (14.02.98) phx
* Alignment list for each section. This fixes the problems
* with optimizations.
* V0.7 (02.01.98) phx
* Implemented optimization OPT_FAR_BRANCH.
* v0.6 (30.10.97) phx
* No more warnings for val@l(rA), where val is > 0x7fff.
* Warnings for optional, 64-bit and supervisor instructions
* can be suppressed.
* v0.5 (03.10.97) phx
* Auto-converting (rA) into 0(rA) had lead to conflicts with terms.
* For example: (x+y)(rA)
* v0.4 (05.07.97) phx
* AA bit in BC instructions is set to allow correct EHF reloction
* (by using AmigaDOS HUNK_RELRELOC16. This should be no problem,
* because absolute branches are not supported by EHF anyway.
* Branch prediction with BCA didn't work correctly.
* Relative branches into other sections are allowed, but the
* user will be warned, because not all object formats / linkers
* support it.
* Omitting zero in load/store instructions is allowed, e.g.
* "rD,(rA)" will be converted into "rD,0(rA)".
* R_PPC_TOC16 support for T_DD- and T_DS-type instructions.
* v0.3 (05.04.97) phx
* An external symbol@l/h/ha, used in d(Rn) addressing mode, got
* R_PPC_ADDR16 relocation instead R_PPC_ADDR16_LO/HI/HA.
* Little-endian support.
* v0.2 (25.03.97) phx
* Writes ELF object for 32-bit PowerPC big-endian. Either absolute
* or ELF output format may be selected. ELF is default for all
* currently supported platforms. PPCasm supports nine different
* relocation types (there are much more...).
* Compiles and works also under NetBSD/amiga (68k).
* Changed function declaration to 'new style' in all sources
* (to avoid problems with '...' for example).
* @l/h/ha is allowed for all displacements.
* v0.1 (11.03.97) phx
* First test version with all PowerPC instructions and most
* important directives. Only raw, absolute output.
* Although all 32- and 64-bit PowerPC instructions are imple-
* mented, too few are really tested till now. I'm expecting many
* bugs in this long list.
* 'la' is the only extended mnemonic, which was implemented as a
* real instruction and not by a macro. It is possible to imple-
* ment all extended mnemonics here, but it would be much work.
* Maybe later, to improve speed. ;)
* v0.0 (21.02.97) phx
* File created.
*/
#define INSTRUCTIONS_C
#include "ppcasm.h"
void instr(struct GlobalVars *,struct ParsedLine *);
char *check_comma(char *);
void pcadd(struct GlobalVars *,unsigned long);
void store_byte(struct GlobalVars *,uint8);
void store_half(struct GlobalVars *,uint16);
void store_word(struct GlobalVars *,uint32);
void store_float(struct GlobalVars *,double);
void store_double(struct GlobalVars *,double);
void store_space(struct GlobalVars *,unsigned long);
static void opt_far_branch(struct GlobalVars *,struct ParsedLine *,
uint32 *,uint32 *,int32 *,char *);
static void swapops(uint32 *,uint32 *);
static int count_operands(struct GlobalVars *,char *);
static bool chk_regindir(char *);
static void move_symbols(struct GlobalVars *,uint32,int32);
static void move_aligned_symbols_offset(struct GlobalVars *,
struct AlignPoint *,uint32,int32);
static void move_aligned_symbols_all(struct GlobalVars *gv,
struct AlignPoint *ap,int32);
struct CPUInstr instructions[] = {
/* standard PowerPC instruction set */
{ 0,"add",0,T_X,31,0,0,(0<<10)+(266<<1)+0 },
{ 0,"add.",0,T_X,31,0,0,(0<<10)+(266<<1)+1 },
{ 0,"addo",0,T_X,31,0,0,(1<<10)+(266<<1)+0 },
{ 0,"addo.",0,T_X,31,0,0,(1<<10)+(266<<1)+1 },
{ 0,"addc",0,T_X,31,0,0,(0<<10)+(10<<1)+0 },
{ 0,"addc.",0,T_X,31,0,0,(0<<10)+(10<<1)+1 },
{ 0,"addco",0,T_X,31,0,0,(1<<10)+(10<<1)+0 },
{ 0,"addco.",0,T_X,31,0,0,(1<<10)+(10<<1)+1 },
{ 0,"adde",0,T_X,31,0,0,(0<<10)+(138<<1)+0 },
{ 0,"adde.",0,T_X,31,0,0,(0<<10)+(138<<1)+1 },
{ 0,"addeo",0,T_X,31,0,0,(1<<10)+(138<<1)+0 },
{ 0,"addeo.",0,T_X,31,0,0,(1<<10)+(138<<1)+1 },
{ 0,"addi",F_SIGNED,T_DI,14,0,0,0 },
{ 0,"addic",F_SIGNED,T_DI,12,0,0,0 },
{ 0,"addic.",F_SIGNED,T_DI,13,0,0,0 },
{ 0,"addis",F_SIGNED,T_DI,15,0,0,0 },
{ 0,"addme",F_SUPP_B,T_X,31,0,0,(0<<10)+(234<<1)+0 },
{ 0,"addme.",F_SUPP_B,T_X,31,0,0,(0<<10)+(234<<1)+1 },
{ 0,"addmeo",F_SUPP_B,T_X,31,0,0,(1<<10)+(234<<1)+0 },
{ 0,"addmeo.",F_SUPP_B,T_X,31,0,0,(1<<10)+(234<<1)+1 },
{ 0,"addze",F_SUPP_B,T_X,31,0,0,(0<<10)+(202<<1)+0 },
{ 0,"addze.",F_SUPP_B,T_X,31,0,0,(0<<10)+(202<<1)+1 },
{ 0,"addzeo",F_SUPP_B,T_X,31,0,0,(1<<10)+(202<<1)+0 },
{ 0,"addzeo.",F_SUPP_B,T_X,31,0,0,(1<<10)+(202<<1)+1 },
{ 0,"and",F_SWAP,T_X,31,0,0,(28<<1)+0 },
{ 0,"and.",F_SWAP,T_X,31,0,0,(28<<1)+1 },
{ 0,"andc",F_SWAP,T_X,31,0,0,(60<<1)+0 },
{ 0,"andc.",F_SWAP,T_X,31,0,0,(60<<1)+1 },
{ 0,"andi.",F_SWAP,T_DI,28,0,0,0 },
{ 0,"andis.",F_SWAP,T_DI,29,0,0,0 },
{ 0,"b",F_SIGNED,T_I,18,0,0,0 },
{ 0,"bl",F_SIGNED,T_I,18,0,0,1 },
{ 0,"ba",0,T_I,18,0,0,2 },
{ 0,"bla",0,T_I,18,0,0,3 },
{ 0,"bc",F_SIGNED,T_B,16,0,0,0 },
{ 0,"bcl",F_SIGNED,T_B,16,0,0,1 },
{ 0,"bca",0,T_B,16,0,0,2 },
{ 0,"bcla",0,T_B,16,0,0,3 },
{ 0,"bcctr",0,T_XLB,19,0,0,(528<<1)+0 },
{ 0,"bcctrl",0,T_XLB,19,0,0,(528<<1)+1 },
{ 0,"bclr",0,T_XLB,19,0,0,(16<<1)+0 },
{ 0,"bclrl",0,T_XLB,19,0,0,(16<<1)+1 },
{ 0,"cmp",0,T_CMP,31,0,0,(0<<1) },
{ 0,"cmpl",0,T_CMP,31,0,0,(32<<1) },
{ 0,"cmpi",F_SIGNED|F_SUPP_B,T_CMP,11,0,0,0 },
{ 0,"cmpli",F_SUPP_B,T_CMP,10,0,0,0 },
{ 0,"cntlzd",F_SWAP|F_SUPP_B|F_64BIT,T_X,31,0,0,(58<<1)+0 },
{ 0,"cntlzd.",F_SWAP|F_SUPP_B|F_64BIT,T_X,31,0,0,(58<<1)+1 },
{ 0,"cntlzw",F_SWAP|F_SUPP_B,T_X,31,0,0,(26<<1)+0 },
{ 0,"cntlzw.",F_SWAP|F_SUPP_B,T_X,31,0,0,(26<<1)+1 },
{ 0,"crand",0,T_X,19,0,0,(257<<1) },
{ 0,"crandc",0,T_X,19,0,0,(129<<1) },
{ 0,"creqv",0,T_X,19,0,0,(289<<1) },
{ 0,"crnand",0,T_X,19,0,0,(225<<1) },
{ 0,"crnor",0,T_X,19,0,0,(33<<1) },
{ 0,"cror",0,T_X,19,0,0,(449<<1) },
{ 0,"crorc",0,T_X,19,0,0,(417<<1) },
{ 0,"crxor",0,T_X,19,0,0,(193<<1) },
{ 0,"dcbf",F_SUPP_D,T_X,31,0,0,(86<<1) },
{ 0,"dcbi",F_SUPP_D|F_SUPER,T_X,31,0,0,(470<<1) },
{ 0,"dcbst",F_SUPP_D,T_X,31,0,0,(54<<1) },
{ 0,"dcbt",F_SUPP_D,T_X,31,0,0,(278<<1) },
{ 0,"dcbtst",F_SUPP_D,T_X,31,0,0,(246<<1) },
{ 0,"dcbz",F_SUPP_D,T_X,31,0,0,(1014<<1) },
{ 0,"divd",F_64BIT,T_X,31,0,0,(0<<10)+(489<<1)+0 },
{ 0,"divd.",F_64BIT,T_X,31,0,0,(0<<10)+(489<<1)+1 },
{ 0,"divdo",F_64BIT,T_X,31,0,0,(1<<10)+(489<<1)+0 },
{ 0,"divdo.",F_64BIT,T_X,31,0,0,(1<<10)+(489<<1)+1 },
{ 0,"divdu",F_64BIT,T_X,31,0,0,(0<<10)+(457<<1)+0 },
{ 0,"divdu.",F_64BIT,T_X,31,0,0,(0<<10)+(457<<1)+1 },
{ 0,"divduo",F_64BIT,T_X,31,0,0,(1<<10)+(457<<1)+0 },
{ 0,"divduo.",F_64BIT,T_X,31,0,0,(1<<10)+(457<<1)+1 },
{ 0,"divw",0,T_X,31,0,0,(0<<10)+(491<<1)+0 },
{ 0,"divw.",0,T_X,31,0,0,(0<<10)+(491<<1)+1 },
{ 0,"divwo",0,T_X,31,0,0,(1<<10)+(491<<1)+0 },
{ 0,"divwo.",0,T_X,31,0,0,(1<<10)+(491<<1)+1 },
{ 0,"divwu",0,T_X,31,0,0,(0<<10)+(459<<1)+0 },
{ 0,"divwu.",0,T_X,31,0,0,(0<<10)+(459<<1)+1 },
{ 0,"divwuo",0,T_X,31,0,0,(1<<10)+(459<<1)+0 },
{ 0,"divwuo.",0,T_X,31,0,0,(1<<10)+(459<<1)+1 },
{ 0,"eciwx",0,T_X,31,0,0,(310<<1) },
{ 0,"ecowx",0,T_X,31,0,0,(438<<1) },
{ 0,"eieio",F_SUPP_D|F_SUPP_A|F_SUPP_B,T_X,31,0,0,(854<<1) },
{ 0,"eqv",F_SWAP,T_X,31,0,0,(284<<1)+0 },
{ 0,"eqv.",F_SWAP,T_X,31,0,0,(284<<1)+0 },
{ 0,"extsb",F_SWAP|F_SUPP_B,T_X,31,0,0,(954<<1)+0 },
{ 0,"extsb.",F_SWAP|F_SUPP_B,T_X,31,0,0,